package com.vhly.aapt;

import com.vhly.aapt.io.OrderInputStream;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 2010-4-26
 * Time: 16:00:54
 */

public class ResChunkHeader {
    public short type;
    public short headerSize;
    public int size;
    public byte[] data;

    public void read(OrderInputStream din) throws IOException {
        type = din.readShort();
        if(type == 0){
            return;
        }
        headerSize = din.readShort();
        size = din.readInt();
//        data = new byte[size];
//        din.read(data, 0, size);
    }

    public void write(DataOutputStream dout) throws IOException {
        dout.writeShort(type);
        data = getData();
        size = data.length;
        headerSize = getHeaderSize();
        dout.writeShort(headerSize);
        dout.writeInt(size);
        dout.write(data);
    }

    public short getHeaderSize() {
        return 8;
    }

    public byte[] getData() {
        return data;
    }
}
